import java.awt.image.BufferedImage;

public class Sprite {
	private BufferedImage[] states;
	private int activeIndex;
	int x, y, speed, width, height;
	boolean up, down, left, right;
	public Sprite(String file, int x, int y, int spriteSize, int speed){
		BufferedImage main;
		main = Utilities.getImage(file);
		states = new BufferedImage[main.getWidth(null) / spriteSize];
		for(int i = 0; i + spriteSize <= main.getWidth(null); i+= spriteSize){
			states[i / spriteSize] = main.getSubimage(i, 0, spriteSize, spriteSize);
		}
		activeIndex = 0;
		this.x = x;
		this.y = y;
		this.speed = speed;
		width = spriteSize;
		height = spriteSize;
		up = false;
		down = false;
		left = false;
		right = false;
	}
	public void setState(int state){
		if(state >= 0 && state < states.length)
			activeIndex = state;
	}
	public int getState(){
		return activeIndex;
	}
	public BufferedImage currentImage(){
		return states[activeIndex];
	}
	public int getX(){
		return x;
	}

	public int getY(){
		return y;
	}

	public int getWidth(){
		return width;
	}

	public int getHeight(){
		return height;
	}

	public void move(){
		if(left){
			x -= speed;
		}
		else if(right){
			x += speed;
		}
		else if(up){
			y -= speed;
		}
		else if(down){
			y += speed;
		}
	}
}
